<!DOCTYPE html>
<html lang="">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>增加账户</title>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <script src="../common/header.js"></script>
    <!-- 内容主体区域 -->
    <div id="LAY_app_body">
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-header">增加账户</div>
                        <div class="layui-card-body">
                            <form class="layui-form layui-form-pane" action="">
                                <div class="layui-row">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">员工名</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="name" lay-verify="name" value="" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">密码</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="passwd" lay-verify="passwd" autocomplete="off" placeholder="请设置密码" value="" class="layui-input">
                                        </div>
                                        <div class="layui-form-mid layui-word-aux">6到16个字符</div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">性别</label>
                                        <div class="layui-input-inline">
                                            <input type="radio" lay-verify="gender" name="gender" value="10" title="男" checked>
                                            <input type="radio" lay-verify="gender" name="gender" value="20" title="女">
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">备注</label>
                                        <div class="layui-input-inline">
                                            <textarea name="remarks" lay-verify="remarks" placeholder="请填写备注" class="layui-textarea"></textarea>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-col-xs12">
                                    <a class="layui-btn" lay-submit lay-filter="formSubmit">确认</a>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'laydate'], function () {
        var $ = layui.$
            , form = layui.form

        form.verify({
            name: function (value) {
                if (value.length < 1) {
                    return '请输入用户名';
                }
            },
            passwd: function (value) {
                if (value.length < 6 || value.length > 16) {
                    return '请输入密码，6到16个字符';
                }
            }
        });
        //监听提交
        form.on('submit(formSubmit)', function (data) {
            layer.msg('提交中', {
                shadeClose: false
                , icon: 16
                , shade: 0.01
            });
            //请求登入接口
            service.post('api/v1/account', {
                gender: parseInt(data.field.gender),
                name: data.field.name,
                passwd: data.field.passwd,
                remarks: data.field.remarks,
            }).then((response) => {
                if (response.code === 200) {
                    //登入成功的提示与跳转
                    layer.msg('添加成功', {
                        offset: '45vh'
                        , icon: 1
                        , time: 2000
                    }, function () {
                        // location.href = '../account_manage/index.html'
                    });
                } else {
                    layer.msg(response.msg, {offset: '45vh', icon: 5, time: 2000});
                }
            }).catch((err) => {
                layer.msg(err.msg, {offset: '45vh', icon: 5, time: 2000});
            })
            return false
        });
    });
</script>
</body>
</html>
